/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.worlds.object;

import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import net.worlds.WorldsException;
import net.worlds.PropChangeHandler;


public abstract class ImageEffect extends GameObject{
    public ImageEffect(String type) throws WorldsException
    {
        super(type);
        addPropChangeHandler("Parent", new PropChangeHandler()
        {

            @Override
            public void handle(Object oldValue, Object value) throws WorldsException {
                onParentChanged((GameObject) oldValue, (GameObject) value);
                if(value instanceof Environment)
                {
                    create();
                }
                else if(value != null && inWorld && !(value instanceof Environment))
                {
                    destroy();
                }
            }
        });
    }
    @Override
    public void addToWorld() throws WorldsException
    {
        if(getParent() instanceof Environment)
            create();
        super.addToWorld();
    }
    @Override
    public void destructor() throws WorldsException
    {
        super.destructor();
        if(getParent() instanceof Environment)
            destroy();
    }
    protected void create()
    {
        world.effect = this;
    }
    protected void destroy()
    {
        world.effect = null;
    }
    public abstract void processImage(BufferedImage img);
}
